package com.pan.admin.module.loanProduct.controller;

import com.pan.admin.common.core.controller.BaseController;
import com.pan.admin.common.core.domain.AjaxResult;
import com.pan.admin.module.loanProduct.entity.po.LoanProductProtocolPO;
import com.pan.admin.module.loanProduct.service.LoanProductProtocolService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 协议Controller
 *
 * @author ZJQ
 * @date 2025-01-02
 */
@RestController
@RequestMapping("/product/loanProduct")
public class LoanProductProtocolController extends BaseController {
    @Autowired
    private LoanProductProtocolService loanProductProtocolService;

    /**
     * 平台配置-查看协议列表
     */
    @PreAuthorize("@ss.hasPermi('product:loanProduct:protocol:query')")
    @GetMapping("/listProtocol")
    public AjaxResult listProtocol(@RequestParam Long loanProductId) {
        loanProductProtocolService.checkDataScope(loanProductId);
        return success(loanProductProtocolService.listLoanProductProtocol(loanProductId));
    }

    /**
     * 平台配置-查看单项协议
     */
    @PreAuthorize("@ss.hasPermi('product:loanProduct:protocol:query')")
    @GetMapping("/getProtocol")
    public AjaxResult getProtocol(@RequestParam Long id) {
        Long loanProductId = loanProductProtocolService.getLoanProductId(id);
        loanProductProtocolService.checkDataScope(loanProductId);
        return success(loanProductProtocolService.getLoanProductProtocol(id));
    }
    /**
     * 平台配置-删除配置协议
     */
    @PreAuthorize("@ss.hasPermi('product:loanProduct:protocol:delete')")
    @DeleteMapping("/deleteProtocol")
    public AjaxResult deleteProtocol(@RequestParam Long id) {
        Long loanProductId = loanProductProtocolService.getLoanProductId(id);
        loanProductProtocolService.checkDataScope(loanProductId);
        return toAjax(loanProductProtocolService.deleteLoanProductProtocol(id));
    }

    /**
     * 平台配置-新增配置协议
     */
    @PreAuthorize("@ss.hasPermi('product:loanProduct:protocol:add')")
    @PutMapping("/insertProtocol")
    public AjaxResult insertProtocol(@RequestBody LoanProductProtocolPO loanProductProtocolPO) {
        loanProductProtocolService.checkDataScope(loanProductProtocolPO.getLoanProductId());
        return toAjax(loanProductProtocolService.insertLoanProductProtocol(loanProductProtocolPO));
    }

    /**
     * 平台配置-更新配置协议
     */
    @PreAuthorize("@ss.hasPermi('product:loanProduct:protocol:edit')")
    @PutMapping("/updateProtocol")
    public AjaxResult updateProtocol(@RequestBody LoanProductProtocolPO loanProductProtocolPO) {
        Long loanProductId = loanProductProtocolService.getLoanProductId(loanProductProtocolPO.getId());
        loanProductProtocolService.checkDataScope(loanProductId);
        return toAjax(loanProductProtocolService.updateLoanProductProtocol(loanProductProtocolPO));
    }

}
